import { fullOrderToProject, changeOrderStep } from "./component/fullOrderToProject.js"
import { taskProcess } from "./component/taskProcess.js"
import { colorDiff, batchColorDiff_2 } from "./component/colorDiff.js"
import { input, select } from "@inquirer/prompts"

import ora from 'ora'

async function run() {
    const funcObj = {
        fullOrderToProject,
        changeOrderStep,
        taskProcess,
        colorDiff,
        batchColorDiff_2
    }

    let orderCode
    let func

    let spinner

    try {
        orderCode = await input({ message: "Enter orderCode", required: true })
        func = await select({
            message: "Select a func",
            choices: [
                {
                    name: "fullOrderToProject",
                    value: "fullOrderToProject",
                    description: "执行完整订单提交到计划",
                },
                {
                    name: "changeOrderStep",
                    value: "changeOrderStep",
                    description: "提交成功但是changeOrderStep失败时使用",
                },
                {
                    name: "colorDiff",
                    value: "colorDiff",
                    description: "两步色差档",
                },
                {
                    name: "batchColorDiff_2",
                    value: "batchColorDiff_2",
                    description: "order下全部生产单执行第二步色差档",
                },
                {
                    name: "taskProcess",
                    value: "taskProcess",
                    description: "任务中心报工",
                },
            ],
        })

        spinner = ora('正在测试接口').start();

        await funcObj[func](orderCode)

        spinner?.succeed('接口调用成功')
    } catch (e) {
        spinner?.info(e.message)
    } finally {
        spinner?.stop()
    }
}

run()
